package org.csu.gp_store.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.csu.gp_store.entity.Evaluation;
import org.csu.gp_store.mapper.EvluationMapper;
import org.csu.gp_store.service.EvaluationService;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EvaluationServiceImpl implements EvaluationService {

    @Autowired
    private EvluationMapper evluationMapper;

    @Override
    public int insertEvaluation(Evaluation evaluation) {
        return evluationMapper.insert(evaluation);
    }

    @Override
    public List<Evaluation> getEvaluationByAccountID(@NotNull Long accountID) {
        QueryWrapper<Evaluation> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("accountID",accountID);
        return evluationMapper.selectList(queryWrapper);
    }

    @Override
    public Evaluation getEvaluationByIndexID(@NotNull Long indexID) {
        return evluationMapper.selectById(indexID);
    }

    @Override
    public int deleteEvaluation(@NotNull Long indexID) {
        return evluationMapper.deleteById(indexID);
    }

    @Override
    public int updateEvaluation(Evaluation evaluation) {
        UpdateWrapper<Evaluation>updateWrapper=new UpdateWrapper<>();
        updateWrapper.eq("indexID",evaluation.getIndexID());
        return evluationMapper.update(evaluation,updateWrapper);
    }

    @Override
    public List<Evaluation> getEvaluationByProductID(@NotNull Long productID) {
        QueryWrapper<Evaluation> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("productID",productID);
        return evluationMapper.selectList(queryWrapper);
    }
}
